﻿<!DOCTYPE html>
<html lang="en">
<head profile="http://a9.com/-/spec/opensearch/1.1/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./site.css" rel="stylesheet">
<title>image/draw</title>
</head>
<body>
<div class="container">
    <h2 id="pkg-overview">package draw</h2>
    <p><code>import "image/draw"</code>
    <p>draw包提供了图像合成函数。参见：<a href="http://golang.org/doc/articles/image_draw.html">http://golang.org/doc/articles/image_draw.html</a></p>
    <h3 id="pkg-index" class="section-header">Index <a class="permalink" href="#pkg-index">&para;</a></h3>
    <ul class="list-unstyled">
        <li><a href="#Quantizer">type Quantizer</a></li>
        <li><a href="#Image">type Image</a></li>
        <li><a href="#Drawer">type Drawer</a></li>
        <li><a href="#Op">type Op</a></li>
        <ul>
            <li><a href="#Op.Draw">func (op Op) Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point)</a></li>
        </ul>
        <li><a href="#Draw">func Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point, op Op)</a></li>
        <li><a href="#DrawMask">func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op Op)</a></li>
    </ul>
    <h3 id="Quantizer">type <a title="View Source" href="http://code.google.com/p/go/source/browse/src/pkg/image/draw/draw.go?name=release#26">Quantizer</a> <a class="permalink" href="#Quantizer">&para;</a></h3>
    <pre>type Quantizer interface {
    <span class="com">// Quantize方法向p中最多增加cap(p)-len(p)个色彩并返回修正后的调色板</span>
    <span class="com">// 返回值更适合（可以更少失真的）将m转换为一个调色板类型的图像</span>
    <span id="Quantizer.Quantize">Quantize</span>(p <a href="https://godoc.org/image/color">color</a>.<a href="https://godoc.org/image/color#Palette">Palette</a>, m <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Image">Image</a>) <a href="https://godoc.org/image/color">color</a>.<a href="https://godoc.org/image/color#Palette">Palette</a>
}</pre>
    <p>Quantizer接口为一个图像生成调色板。</p>
    <h3 id="Image">type <a title="View Source" href="http://code.google.com/p/go/source/browse/src/pkg/image/draw/draw.go?name=release#20">Image</a> <a class="permalink" href="#Image">&para;</a></h3>
    <pre>type Image interface {
    <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Image">Image</a>
    <span id="Image.Set">Set</span>(x, y <a href="https://godoc.org/builtin#int">int</a>, c <a href="https://godoc.org/image/color">color</a>.<a href="https://godoc.org/image/color#Color">Color</a>)
}</pre>
    <p>Image接口比image.Image接口多了Set方法，该方法用于修改单个像素的色彩。</p>
    <h3 id="Drawer">type <a title="View Source" href="http://code.google.com/p/go/source/browse/src/pkg/image/draw/draw.go?name=release#49">Drawer</a> <a class="permalink" href="#Drawer">&para;</a></h3>
    <pre>type Drawer interface {
    <span class="com">// 对齐图像dst的r.Min和src的sp点，然后将src绘制到dst上的结果来替换矩形范围内的图像</span><span class="com"></span>
    <span id="Drawer.Draw">Draw</span>(dst <a href="#Image">Image</a>, r <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Rectangle">Rectangle</a>, src <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Image">Image</a>, sp <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Point">Point</a>)
}</pre>
    <p>Drawer包含Draw方法。</p>
    <pre>var <span id="FloydSteinberg">FloydSteinberg</span> <a href="#Drawer">Drawer</a> = floydSteinberg{}</pre>
    <p>FloydSteinberg是采用Src操作并实现了Floyd-Steinberg误差扩散算法的Drawer。</p>
    <h3 id="Op">type <a title="View Source" href="http://code.google.com/p/go/source/browse/src/pkg/image/draw/draw.go?name=release#33">Op</a> <a class="permalink" href="#Op">&para;</a></h3>
    <pre>type Op <a href="https://godoc.org/builtin#int">int</a></pre>
    <p>Op是Porter-Duff合成的操作符。</p>
    <pre>const (
    <span class="com">// 源图像透过遮罩后，覆盖在目标图像上（类似图层）</span>
    <span id="Over">Over</span> <a href="#Op">Op</a>  = <a href="https://godoc.org/builtin#iota">iota</a>
    <span class="com">// 源图像透过遮罩后，替换掉目标图像</span>
    <span id="Src">Src</span>
)</pre>
    <h4 id="Op.Draw">func (Op) <a title="View Source" href="http://code.google.com/p/go/source/browse/src/pkg/image/draw/draw.go?name=release#44">Draw</a> <a class="permalink" href="#Op.Draw">&para;</a></h4>
    <pre class="funcdecl">func (op <a href="#Op">Op</a>) Draw(dst <a href="#Image">Image</a>, r <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Rectangle">Rectangle</a>, src <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Image">Image</a>, sp <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Point">Point</a>)</pre>
    <p>Draw方法通过使用Op参数调用包的Draw函数实现了Drawer接口。</p>
    <h3 id="Draw">func <a title="View Source" href="http://code.google.com/p/go/source/browse/src/pkg/image/draw/draw.go?name=release#97">Draw</a> <a class="permalink" href="#Draw">&para;</a></h3>
    <pre class="funcdecl">func Draw(dst <a href="#Image">Image</a>, r <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Rectangle">Rectangle</a>, src <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Image">Image</a>, sp <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Point">Point</a>, op <a href="#Op">Op</a>)</pre>
    <p>Draw函数使用nil的mask参数调用DrawMask函数。</p>
    <h3 id="DrawMask">func <a title="View Source" href="http://code.google.com/p/go/source/browse/src/pkg/image/draw/draw.go?name=release#103">DrawMask</a> <a class="permalink" href="#DrawMask">&para;</a></h3>
    <pre class="funcdecl">func DrawMask(dst <a href="#Image">Image</a>, r <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Rectangle">Rectangle</a>, src <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Image">Image</a>, sp <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Point">Point</a>, mask <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Image">Image</a>, mp <a href="https://godoc.org/image">image</a>.<a href="https://godoc.org/image#Point">Point</a>, op <a href="#Op">Op</a>)</pre>
    <p>对齐目标图像dst的矩形r左上角、源图像src的sp点、遮罩mask的mp点，根据op修改dst的r矩形区域内的内容，mask如果为nil则视为完全透明。</p>
</div>
</body>
</html>
